/**
 * 公用参数
 */
var name=''//就诊人
var code=""
var pcode=""
var hostcode=""
var titleInfo=null
var otherInfo=null
var paytype='xx'
var cardno=null,
    cardtype=null,
    idcard=null,
    idcardtype=null

/**
 * 默认加载
 * @type {{init: Window.process.init, public: Window.process.public}}
 */
window.process = {
    init() {
        this.initData();

    },
    initData() {
        var paramsData = getUrlParamsCode();
        name= paramsData['name'];
        cardno= paramsData['cardno'];
        cardtype= paramsData['cardtype'];
        idcard= paramsData['idcard'];
        idcardtype= paramsData['idcardtype'];
         titleInfo=JSON.parse(localStorage.getItem('titleInfo'))
         otherInfo=JSON.parse(localStorage.getItem('otherInfo'))
        var Data={
            list:titleInfo
        };
        var listHtml = template('list_data', Data);
        $("#list_data_content").html(listHtml);
        $('#name').html(name)
        this.public();

    },
    
    callbackFrom(data){
        var data=data.obj
        if(paytype=='xs'){
            WeixinJSBridge.invoke(
                'getBrandWCPayRequest', {
                    "appId":data.appId,     //公众号名称，由商户传入
                    "timeStamp":data.timeStamp,         //时间戳，自1970年以来的秒数
                    "nonceStr":data.nonceStr, //随机串
                    "package":data.package,
                    "signType":"MD5",         //微信签名方式：
                    "paySign":data.paySign //微信签名
                },
                function(res){
                    if(res.err_msg == "get_brand_wcpay_request:ok" ){
                        $.alert({
                            title: '提示',
                            text: '支付成功',
                            onOK: function () {
                               window.location.href='make_success.html'
                            }
                        });
                    }else{
                        $.alert({
                            title: '订单成功',
                            text: '待支付，请在一分钟内完成支付',
                            onOK: function () {
                               window.location.href='../index.html'
                            }
                        });
                    }
                });
        }else{
            $.alert('到院支付')
        }
      
    },
    public() {
        var  that=this
        //选择支付方式
        $('.m2 .content .item').click(function () {
            $(this).addClass('on').siblings().removeClass('on');
            paytype=$(this).attr('data-pay');
        });
       //提交

        $('#fromBtn').click(function () {
            var api='/appApponits/add'
            var data={
                openid:localStorage.openid,
                responsetype:localStorage.responsetype,
                regno:timestamp(),
                channel:1,  //默认1
                hoscode:titleInfo.hostcode,
                deptcode1:titleInfo.deptcode1,
                deptcode2:titleInfo.deptcode2,
                cardno:cardno?cardno:'',  //传空
                cardtype:cardtype?cardtype:'', //传空
                patientname:name?name:otherInfo.realName,
                idcard:idcard?idcard:otherInfo.idCard,
                idcardtype:idcardtype?idcardtype:otherInfo.idcardtype,
                doctorcode:titleInfo.doctorcode,
                titletype:titleInfo.titletype,
                regdate:titleInfo.day,
                reghalf:titleInfo.reghalf,
                reghour:titleInfo.reghour,
                regtype:1,
                extparam:titleInfo.extparam,
                phone:otherInfo.phone,
                pidtype:'wxzf',
                paytype:paytype
            }
            postAjax(api,data,that.callbackFrom)
        })


    }
};

/**
 * 启动方法执行
 */
process.init();



